package com.beauty.dressing.module.mine.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.beauty.dressing.R;
import com.beauty.dressing.common.base.BaseActivity;
import com.beauty.dressing.common.bean.AgreementBean;
import com.beauty.dressing.common.bean.LeaseBean;
import com.beauty.dressing.common.bean.RefuseJudgeBean;
import com.beauty.dressing.common.bean.User;
import com.beauty.dressing.common.utils.Constants;
import com.beauty.dressing.logic.control.LBController;
import com.beauty.dressing.module.mine.persenter.MyLeaseControl;
import com.beauty.dressing.module.mine.persenter.MyLeasePresenter;

/**
 * 协议内容
 */
public class ProtocolActivity extends BaseActivity {
    TextView protocol_context, title_txt;
    LeaseBean leaseBean;
    User user;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_protocol);
    }

    @Override
    public void findView() {
        findViewById(R.id.agree).setOnClickListener(this);
        findViewById(R.id.refuse).setOnClickListener(this);
        findViewById(R.id.left_img_btn).setOnClickListener(this);
        title_txt = findViewById(R.id.title_txt);
        title_txt.setText("丢弃协议");
        protocol_context = findViewById(R.id.protocol_context);
    }

    @Override
    public void initData() {
        user = LBController.getInstance().getCacheManager().getLoginUser();
        if (getIntent().getStringExtra(Constants.AGREEMENT) != null) {
            myLeasePresenter.agreement(getIntent().getStringExtra(Constants.AGREEMENT));
            if (getIntent().getStringExtra(Constants.AGREEMENT).equals("1")) {
                title_txt.setText("退租协议");
            } else {
                title_txt.setText("丢弃协议");
            }
        }
        if (getIntent().getSerializableExtra("data") != null) {
            leaseBean = (LeaseBean) getIntent().getSerializableExtra("data");
        }
    }

    MyLeasePresenter myLeasePresenter = new MyLeasePresenter(new MyLeaseControl() {
        @Override
        public void onAgreement(boolean isSuccess, int code, String message, AgreementBean bean) {
            super.onAgreement(isSuccess, code, message, bean);
            protocol_context.setText(bean.getContent());
        }

        @Override
        public void onRefuseJudge(boolean isSuccess, int code, String message, int type, RefuseJudgeBean bean) {
            super.onRefuseJudge(isSuccess, code, message, type, bean);
            if (isSuccess) {
                startActivity(new Intent(context, MyLeaseCostingActivity.class)
                        .putExtra(Constants.REFUSEJUDGEBEAN, bean).putExtra(Constants.TYPE, type).putExtra(Constants.ACTIVITYDATA, leaseBean));
            }
        }
    });

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.agree://判断点击类型 2丢弃 1退租
                if (getIntent().getStringExtra(Constants.AGREEMENT).equals("2"))
                    startActivity(new Intent(context, ClearingActivity.class)
                            .putExtra(Constants.AGREEMENT, getIntent().getStringExtra(Constants.AGREEMENT))
                            .putExtra("data", leaseBean));
                else if (getIntent().getStringExtra(Constants.AGREEMENT).equals("1")) {
//                    myLeasePresenter.refuseJudge(user.token, user.member_id, bean.getId());
                    myLeasePresenter.refuseJudge("3889f68da98eea80ffaf64ae8cae6ff4347a435c", 1, leaseBean.getId());
                }
                break;
            case R.id.refuse:
                this.finish();
                break;
            case R.id.left_img_btn:
                this.finish();
                break;
        }
    }
}
